package com.nkzy.controller;

import com.nkzy.models.PageQuery;
import com.nkzy.models.R;
import com.nkzy.models.TableData;
import com.nkzy.pojo.Dept;
import com.nkzy.service.IDeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dept")
@RequiredArgsConstructor
public class DeptController {

    private final IDeptService deptService;

    @GetMapping("/pages")
    public TableData<Dept> pages(Dept dept, PageQuery pageQuery) {
        return deptService.selectList(dept, pageQuery);
    }


    @GetMapping("/{id}")
    public R<Dept> selectById(@PathVariable Long id) {
        var dept = deptService.selectById(id);
        return R.ok(dept);
    }

    @PostMapping
    public R<Void> addDept(@RequestBody Dept dept) {
        deptService.addDept(dept);
        return R.ok();
    }

    @PutMapping
    public R<Void> updateDept(@RequestBody Dept dept) {
        deptService.updateDept(dept);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    public R<Void>  deleteDeptById(@PathVariable  Long id){
        deptService.deleteDeptById(id);
        return R.ok();
    }

}
